<template>
	<view>
		<xl-navbar title="权限判断"></xl-navbar>
		<button @tap="applyCameraPermission('camera')">申请相机权限</button>
		<button @tap="applyPhonePermission('contact')">申请电话权限</button>
		<button @tap="applyReadexternal('album')">读取照片</button>
		<button @tap="getLocation">获取当前位置</button>
	</view>
</template>

<script setup>
	async function applyCameraPermission(permission) {
		if (!await uni.$xl.service.checkPermission(permission)) return
		//选择照片这个是摄像头和相册 多个权限 那么在这写两次就好了
		//if (!await permissionStore.requstPermission('CAMERA')) return
		//if (!await permissionStore.requstPermission('READ_EXTERNAL_STORAGE')) return
		uni.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['camera'],
			success: (res) => {
				console.log(res)
			}
		});
	}
	
	async function applyPhonePermission(permission) {
		/* #ifdef APP */
		if (!await uni.$xl.service.checkPermission(permission)) return
		/* #endif */
		uni.makePhoneCall({
			phoneNumber: '10086'
		});
	}
	async function applyReadexternal(permission) {
		if (!await uni.$xl.service.checkPermission(permission)) return
		uni.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album'],
			success: (res) => {
				console.log(res)
			}
		});
	}
	
	async function getLocation() {
		if (!await uni.$xl.service.checkPermission('location')) return
		if(!checkSystemEnableLocation()) {
			openLocationSetting()
		}
	}
</script>

<style lang="scss" scoped>
	
</style>